package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.database.SqlManager;
import com.ymttest.utils.EnvSetup;

public class YmtAddressWapper {
	SqlManager manage;

	public YmtAddressWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}

	/**
	 * 根据用户ID和地址获取用户的Adress信息
	 * @return
	 */
	public Map selectAdressByUserIdAndAddress(int userId, String baseAddress, String detailAdress){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userId", userId);
		map.put("baseAddress", baseAddress);
		map.put("detailAdress", detailAdress);
		List<Map> addressList = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtAdressMapper.selectAdressByUserIdAndAddress", map);
		manage.commit();
		if (addressList.size() > 0) {
			return addressList.get(0);
		}
		return null;
	}
	
	/**
	 * 获取用户的地址列表
	 * @return
	 */
	public List<Map> getAdressByUserId(int userId){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userId", userId);
		List<Map> addressList = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtAdressMapper.getAdressByUserId", map);
		manage.commit();
		return addressList;
	}
	
	public void close(){
		manage.close();
		manage = null;
	}
}
